package com.softstao.guoyu.wxapi;


import android.os.Bundle;
import android.util.Log;

import com.softstao.guoyu.global.SharePreferenceManager;
import com.tencent.mm.sdk.modelbase.BaseResp;
import com.tencent.mm.sdk.modelmsg.SendAuth;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.weixin.view.WXCallbackActivity;

/**
 * Created by vaikus on 17/7/24.
 */
public class WXEntryActivity extends WXCallbackActivity {
    @Override
    public void onResp(BaseResp resp) {
        if(SharePreferenceManager.getInstance().isOauthVerify()){
            try {
                Log.e("code", ((SendAuth.Resp) resp).code);
            }catch (NullPointerException e){
                e.printStackTrace();
            }
            SendAuth.Resp baseResp= new SendAuth.Resp();
            Bundle bundle = new Bundle();
            resp.toBundle(bundle);
            baseResp.fromBundle(bundle);
            resp=baseResp;
            try {
                Log.e("code", baseResp.code);
            }catch (NullPointerException e){
                e.printStackTrace();
            }
            SharePreferenceManager.getInstance().setWxCode(baseResp.code);
            SharePreferenceManager.getInstance().setOauthVerify(false);
            SharePreferenceManager.getInstance().getListener().onComplete(SHARE_MEDIA.WEIXIN,0,null);
            finish();
            return;
        }
        if(this.mWxHandler != null) {
            this.mWxHandler.getWXEventHandler().onResp(resp);
        }

        this.finish();
    }
}
